package com.fz.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.fz.entity.Complaint;
import com.fz.entity.Repair;
import com.fz.mapper.ComplaintMapper;
import com.fz.service.ComplaintService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author fz
 * @since 2024-08-20
 */
@Service
public class ComplaintServiceImpl extends ServiceImpl<ComplaintMapper, Complaint> implements ComplaintService {
@Resource
    ComplaintMapper complaintMapper;
@Override
public Boolean reject(Long id,Integer statue,Integer statu){
    return this.updateById(new Complaint(id,statue,statu));
}
@Override
    public boolean check(Long id,String field,String value)
    {
        QueryWrapper<Complaint> wrapper=new QueryWrapper<>();
        wrapper.eq(field,value);
        System.out.println(id);
        if(null!=id)
        {
            wrapper.ne("id",id);
        }
        return this.count(wrapper)==0;
    }
    @Override
    public Boolean pass(Long id,Integer status,Integer statu){return this.updateById(new Complaint(id,status,statu));}
    @Override
    public List<Complaint> search(String input){
        QueryWrapper<Complaint> wrapper=new QueryWrapper<>();
        wrapper.like("type",input);
        return this.list(wrapper);
    }
    @Override
    public boolean del(Long id, Integer status) {
        return this.updateById(new Complaint(id,status));
    }

    @Override
    public Page<Complaint> getList(Long userId, Integer pageNo, Integer pageSize) {
        QueryWrapper<Complaint> wrapper = new QueryWrapper<>();
        Page<Complaint>complaintPage;
        wrapper.eq("user_id", userId)
                .ne("status",-1)
                .orderByDesc("handle_time");
        complaintPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return complaintPage;
    }

    @Override
    public Boolean add(Integer userId, String type, String content){

        return this.save(new Complaint(userId,type,content));
    }
    @Override
    public Page<Complaint> search(String input, Integer pageNo, Integer pageSize){
        QueryWrapper<Complaint> wrapper=new QueryWrapper<>();
        Page<Complaint>repairPage;
        wrapper.like("type",input)
                .ne("status",-1)
                .orderByDesc("handle_time");
        repairPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return this.page(new Page<>(pageNo, pageSize),wrapper);
    }
    @Override
    public Page<Complaint> showList(Integer pageNo, Integer pageSize) {
        QueryWrapper<Complaint> wrapper = new QueryWrapper<>();
        Page<Complaint>repairPage;
        wrapper.ne("status",-1)
                .orderByDesc("handle_time");
        repairPage = this.page(new Page<>(pageNo, pageSize), wrapper);
        return this.page(new Page<>(pageNo, pageSize),wrapper);
    }
}
